home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- #Tag 0x00000700
- #**************************************************************************
- #*
- #* Copyright (c) 1993 Silicon Graphics, Inc.
- #* All Rights Reserved
- #*
- #* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
- #*
- #* The copyright notice above does not evidence any actual of intended
- #* publication of such source code, and is an unpublished work by Silicon
- #* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
- #* the property of Silicon Graphics, Inc. Any use, duplication or
- #* disclosure not specifically authorized by Silicon Graphics is strictly
- #* prohibited.
- #*
- #* RESTRICTED RIGHTS LEGEND:
- #*
- #* Use, duplication or disclosure by the Government is subject to
- #* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
- #* Technical Data and Computer Software clause at DFARS 52.227-7013,
- #* and/or in similar or successor clauses in the FAR, DOD or NASA FAR
- #* Supplement. Unpublished - rights reserved under the Copyright Laws of
- #* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
- #* Shoreline Blvd., Mountain View, CA 94039-7311
- #**************************************************************************
- #*
- #* File: mkcentpr
- #*
- #* $Revision: 1.32 $
- #*
- #* Description: Shell script for adding a Centronics based printer to
- #* the System V spooling system.
- #*
- #* Usage: mkcentpr
- #*
- #* Selection of all installation parameters such as printer name
- #* will be done interactively.
- #*
- #* Updated for print 1.7 (major changes for print 1.7). This script no
- #* longer parses the output of "lputil list". It now uses
- #* /usr/lib/print/modelinfo and /usr/lib/print/modinfofltr to build
- #* the menus that the user sees. This was done because with PPD files
- #* (introduced in Impressario 2.2) it is possible to have a large number
- #* of supported printers. The older code for this routine could not handle
- #* a large number of printers (it would overflow string variables).
- #*
- #**************************************************************************
-
-
- # Well known directories and programs
-
- LPUTIL_DIR=/usr/lib
- LPUTIL=$LPUTIL_DIR/lputil
- AWK_DIR=/usr/bin
- AWK=$AWK_DIR/nawk
- OUT_FILT="/usr/bin/pg -s -p more... -e"
- SPOOL_DIR=/var/spool/lp
- LPSTAT=/usr/bin/lpstat
- MODELINFO=/usr/lib/print/modelinfo
- MODELINFOFILTER="/usr/lib/print/modinfofltr -l centronics"
-
- # Global variables
-
- PNAME=""
- DEF_CENT_DEV=""
- CENT_DEV=""
- PMODEL_LIST=""
- PTYPE_LIST=""
- POPT_LIST=""
- NUM_MODELS=0
- NUM_VENDORSS=0
- TYPE_ID=""
- VENDOR_ID=""
- TYPE_NAME=""
- MODEL_NAME=""
- OPTION_STR=""
-
-
- #
- # Checks that we are the super-user and verifies
- # that the System V spooling system is present
- #
- CheckPermSpooler()
- {
- cid=`/usr/bin/id | $AWK '{print substr($1,index($1,"("))}'`;
- if [ "$cid" != "(root)" ]; then
- echo "You must be logged in as root to use this program."
- exit 1;
- fi
- if [ ! -r $SPOOL_DIR ]; then
- echo "The System V spooling system is not installed on this system."
- exit 1
- fi
- }
-
-
- #
- # Determines the default parallel port based on the
- # system IP number.
- #
- FindDefPort()
- {
- # Assume we have /dev/plp
- DEF_CENT_DEV=/dev/plp
-
- }
-
-
- #
- # Extracts the model file name from a string similar to:
- # "laserwriter_model%CENTRONICS%Apple LaserWriter II%FACEUP=0".
- # Would return "laserwriter_model".
- #
- GetModelFileName()
- {
- MODEL_NAME=`echo $* | $AWK -F\% '{
- printf("%s\n",$1)
- }'`
- }
-
-
- #
- # Extracts the printer type from a string similar to:
- # "laserwriter_model%CENTRONICS%Apple LaserWriter II%FACEUP=0"
- # Would return "Apple LaserWriter II".
- #
- GetPrinterType()
- {
- TYPE_NAME=`echo $* | $AWK -F\% '{
- printf("%s\n",$3)
- }'`
- }
-
-
- #
- # Extracts the printer model file options from a string similar to:
- # "laserwriter_model%CENTRONICS%Apple LaserWriter II%FACEUP=0"
- # Would return "FACEUP=0".
- #
- GetPrinterOptions()
- {
- OPTION_STR=`echo $* | $AWK -F\% '{
- printf("%s\n",$4)
- }'`
- }
-
- #
- # Test for pure decimal positive integer input
- #
- # Expects $1 to be the value to check. Returns 0 if
- # OK, 1 if invalid positive integer or if more than one
- # argument specified
- #
- VerifyInt()
- {
- if [ $# -eq 0 ]; then
- return 0
- fi
- if [ $# -gt 1 ]; then
- return 1
- fi
- echo $1 | egrep -s '^[0-9]*$'
- return $?
- }
-
-
- #
- # Test for a valid printer name (i.e. 14 chars max, A-Za-z0-9_
- # only and no spaces)
- #
- VerifyPname()
- {
- if [ $# -gt 1 ]; then
- return 1
- fi
- echo $1 | egrep -s '^[A-Za-z0-9_]*$'
- if [ $? -eq 1 ]; then
- return 1
- fi
- if [ `echo $1 | $AWK '{ print length($1) }'` -gt 14 ]; then
- return 1
- else
- return 0
- fi
- }
-
-
- #########################################################################
- #
- # Main program
- #
-
- #
- # Ensure that we are root and that the main System V
- # spooling system directory is present
- #
- CheckPermSpooler
-
- #
- # Display an intro message
- #
- echo "Centronics Printer Installation Tool\n"
-
- #
- # Query user for a name for this printer
- #
- while [ "$PNAME" = "" ]; do
- echo "Enter new printer name (14 chars max.): \c"
- read PNAME
- VerifyPname $PNAME
- if [ $? -eq 1 ]; then
- echo "Invalid response: Name must be 14 chars max. (A-Za-z0-9_ only)"
- PNAME=""
- fi
- if [ "$PNAME" = "" ]; then
- continue
- fi
- /bin/ls $SPOOL_DIR/member/$PNAME 2> /dev/null 1> /dev/null
- if [ $? -eq 0 ]; then
- echo ""
- echo "WARNING: Printer $PNAME already exists."
- echo '\nChoose a new name (y/n)[y]? \c'
- read yn
- if [ \( "$yn" != "n" \) -a \( "$yn" != "N" \) ]; then
- PNAME=""
- fi
- fi
- done
- echo " "
-
- #
- # Determine the default parallel port
- #
- FindDefPort
-
- #
- # Query the user for the device port
- #
- while [ "$CENT_DEV" = "" ]; do
- echo "Enter centronics device port [$DEF_CENT_DEV]: \c"
- read CENT_DEV
- if [ "$CENT_DEV" = "" ]; then
- CENT_DEV=$DEF_CENT_DEV
- fi
- done
- echo " "
-
- #
- # Sanity check the device port by seeing if we can ls it
- #
- /bin/ls $CENT_DEV 2> /dev/null 1> /dev/null
- if [ $? -ne 0 ]; then
- echo "WARNING: Device file $CENT_DEV does not exist."
- echo '\nContinue installation (y/n)[n]? \c'
- read yn
- if [ \( "$yn" != "y" \) -a \( "$yn" != "Y" \) ]; then
- exit 1
- fi
- echo " "
- fi
-
- #
- # Check to see if another printer is using this port
- #
- in_use=`cd $SPOOL_DIR/member; egrep -l $CENT_DEV * 2> /dev/null`
- if [ "$in_use" != "" ]; then
- echo "WARNING: Device file $CENT_DEV is currently used by printer(s):"
- for p in $in_use; do
- echo "\t\t$p"
- done
- echo '\nContinue installation (y/n)[n]? \c'
- read yn
- if [ \( "$yn" != "y" \) -a \( "$yn" != "Y" \) ]; then
- exit 1
- fi
- echo " "
- fi
-
- #
- # Use modelinfo and modinfofltr to build menus of supported printer
- # vendors and printer models.
- #
- echo "Determining printer vendor list..."
- echo " "
-
- # The outer loop is because we allow the user to press return onthe
- # secoond menu to jump back to the first menu.
-
- GOT_VENDOR_ID=""
- while [ "$GOT_VENDOR_ID" = "" ]; do
-
- # Get the user choice of vendor. User sees something like:
- # 1. GENERIC
- # 2. HP
- # 3. TEK
-
- VENDOR_ID=""
- while [ "$VENDOR_ID" = "" ]; do
- MODELS_LIST=`$MODELINFO | $MODELINFOFILTER`
- NUM_VENDORS=$? # modinfoftr returns number of menu items
- echo "$MODELS_LIST" | $OUT_FILT
- if [ $NUM_VENDORS -eq -1 ]; then
- echo "ERROR. $MODELINFOFILTER returns -1. -1 indicates"
- echo "program called with invalid arguments."
- fi
- if [ $NUM_VENDORS -eq 0 ]; then
- echo "ERROR: No parallel printers appear to be supported on this system."
- echo " Check that print software has been installed."
- exit 1
- fi
- echo " "
- echo "Select printer vendor to use: \c"
- read VENDOR_ID
- VerifyInt $VENDOR_ID
- if [ $? -eq 1 ]; then
- echo "Invalid response: must be number between 1 and $NUM_VENDORS"
- VENDOR_ID=""
- fi
- if [ "$VENDOR_ID" = "" ]; then
- continue
- fi
- if [ \( $VENDOR_ID -eq 0 \) -o \( $VENDOR_ID -gt $NUM_VENDORS \) ]; then
- echo "Invalid response: must be between 1 and $NUM_VENDORS"
- VENDOR_ID=""
- fi
- done
-
- GOT_VENDOR_ID="1" # Force exit from main loop
-
- # Now list the printer drivers supported for the selected vendor:
- # Get user choice for model. User sees something like:
-
- # 1. APPLE LASERWRITER II
- # 2. APPLE LASERWRITER IIF
- # 3. APPLE LASERWRITER IIG
- # 4. APPLE LASERWRITER IINT
- # 5. APPLE LASERWRITER IINTX
- # 6. APPLE LASERWRITER PLUS
-
- TYPE_ID=""
- while [ "$TYPE_ID" = "" ]; do
-
- $MODELINFO | $MODELINFOFILTER -v$VENDOR_ID | egrep -i "\(POSTSCRIPT\)" 2> /dev/null 1> /dev/null
- PPD_FOUND=$?
-
- $MODELINFO | $MODELINFOFILTER -v$VENDOR_ID | egrep "IMPRESSARIO LICENSE REQUIRED" 2> /dev/null 1> /dev/null
- LICENSE_NEEDED=$?
-
- echo " "
- MODELS_LIST=`$MODELINFO | $MODELINFOFILTER -v$VENDOR_ID`
- NUM_MODELS=$? # modinfoftr returns number of menu items
- echo "$MODELS_LIST" | $OUT_FILT
- if [ $NUM_MODELS -eq -1 ]; then
- echo "ERROR. $MODELINFOFILTER returns -1. -1 indicates"
- echo "program called with invalid arguments."
- fi
-
- if [ $NUM_MODELS -eq 0 ]; then
- echo "ERROR: No parallel printers appear to be supported for this choice."
- echo " Check that print software has been installed."
- if [ "$NUM_VENDORS" = "1" ]; then
- exit 1
- fi
- echo ""
- echo "Press Enter to return to last menu.\c"
- read TYPE_ID
- TYPE_ID=1 # Bogus value to get out of this loop
- GOT_VENDOR_ID="" # Re-start main loop to go back to last menu
- continue
- fi
-
- if [ "$PPD_FOUND" = "0" ]; then
- echo ""
- echo "NOTE: Printer model names followed by \"(POSTSCRIPT)\" will only work"
- echo "with printers that have built-in PostScript support. Some of"
- echo "these printers do not come with built-in PostScript and it must"
- echo "be purchased from the printer vendor as a separate option."
- fi
-
- if [ "$LICENSE_NEEDED" = "0" ]; then
- echo ""
- echo "Printer model names followed by \"(IMPRESSARIO LICENSE REQUIRED)\" will"
- echo "need an optional Impressario license. See the Impressario release notes"
- echo "for details or the file /usr/lib/print/data/psrip_expired_msg"
- fi
-
- echo ""
- echo "Select printer model to use (press Enter for last menu): \c"
- read TYPE_ID
- if [ "$TYPE_ID" = "" ]; then
- TYPE_ID=1 # Bogus value to get out of this loop
- GOT_VENDOR_ID="" # Re-start main loop to go back to last menu
- echo ""
- continue
- fi
- VerifyInt $TYPE_ID
- if [ $? -eq 1 ]; then
- echo "Invalid response: must be number between 1 and $NUM_MODELS"
- TYPE_ID=""
- fi
- if [ \( $TYPE_ID -eq 0 \) -o \( $TYPE_ID -gt $NUM_MODELS \) ]; then
- echo "Invalid response: must be between 1 and $NUM_MODELS"
- TYPE_ID=""
- fi
- done
-
- done
-
- #
- # Inform the user of what comes next
- #
- echo " "
- echo "Installing parallel printer $PNAME..."
- echo " "
-
- #
- # Get the model info string for the selected printer and pull out
- # the parts we need.
- #
-
- modelstring=`$MODELINFO | $MODELINFOFILTER -v$VENDOR_ID -c$TYPE_ID`
- if [ $? -eq -1 ]; then
- echo "ERROR. $MODELINFOFILTER returns -1. -1 indicates"
- echo "program called with invalid arguments."
- fi
-
- GetModelFileName $modelstring
- GetPrinterType $modelstring
- GetPrinterOptions $modelstring
-
- #
- # Install the printer. We use awk to execute the lputil command
- # because we want the OPTION_STR strings handled properly (i.e.
- # with the proper quoting).
- #
- echo $LPUTIL add $CENT_DEV $MODEL_NAME \
- $PNAME NAME=\'\"$TYPE_NAME\"\' $OPTION_STR | $AWK '{
- rv = system($0)
- exit rv
- }'
- if [ $? -ne 0 ]; then
- echo "ERROR: Installation of new printer failed."
- echo " $LPUTIL command failed."
- exit 1
- fi
-
- #
- # Inform the user of what has happened
- #
- echo " "
- echo "Centronics Printer $PNAME has been installed"
- echo " "
- echo "Here is your printing environment:"
- echo " "
- $LPSTAT -t | $OUT_FILT
-
- #
- # Return a successful exit code
- #
- exit 0
-